package com.gw.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.gw.bean.Student;
import com.gw.service.StudentService;
@RequestMapping(value = "/student")
@Controller
public class StudentController {
	@Resource 
	private StudentService studentService;
	@RequestMapping(value = "/addStudent.do")
	public ModelAndView addStudent(Student student) {
		String str="注册失败";
		ModelAndView modelAndView=new ModelAndView();
		int nums=studentService.addStudent(student);
		if (nums>0) {
			str="学生【"+student.getName()+"】注册成功";	
		}
		modelAndView.addObject("info",str);
		modelAndView.setViewName("result");
		return modelAndView;
	}
	@ResponseBody
	@RequestMapping(value = "/queryStudents.do")
	public List<Student> queryStudents(){
		List<Student> list=new ArrayList<Student>();
		list=studentService.findStudent();
		return list;
	}
}
